package com.rbac.web.db;

import com.baomidou.mybatisplus.annotation.TableName;
import com.rbac.web.model.UserRole;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

/**
 * @author gengaoliu
 */
@Getter
@Setter
@ToString
@SuperBuilder
@TableName("user_role")
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
public class UserRoleDO extends BaseDO {
  private Integer userId;
  private Integer roleId;

  public static UserRoleDO from(UserRole userRole) {
    return UserRoleDO.builder()
        .id(userRole.getId())
        .createTime(userRole.getCreatedTime())
        .userId(userRole.getUserId())
        .roleId(userRole.getRoleId())
        .build();
  }

  public UserRole to() {
    return UserRole.builder()
        .id(this.getId())
        .createdTime(this.getCreateTime())
        .userId(this.getUserId())
        .roleId(this.getRoleId())
        .build();
  }
}
